//Author Rahul Ashok for SUTD//Author Rahul Ashok for SUTD//Author Rahul Ashok for SUTD

package fllab.com.bean;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

import fllab.com.entitiy.LightEntity;
//import fllab.com.entitiy.ProximityEntity;
import fllab.com.service.FLabService;

public class FLabBean {

	private Integer selectedMote;
	private String power_usage1 = "0";
	private String power_usage2 = "0";
	private String Light_Value;
	private String Humidity_Value;
	private String Proximity_Value;
	private String Date_Value;
	private String Time_Value;
	private String Location;
	private Integer flag_1;
	private Integer flag_2;
	
	private String Sound_Value;
	private String Location_Label = "";
	private String Light_Label = "";
	private String Proximity_Label = "";
	private String Temp_Label = "";
	private String Sound_Label = "";
	private String Humidity_Label = "";
	private String Date_Label = "";
	private String Time_Label = "";
	private String sM_Label = "";
	private String Temp_Value;
	private String Message="";
	private String Message1="";
	private String p_Name;
	
	private String sM;
	
	
	
	


	public Integer getFlag_1() {
		return flag_1;
	}

	public void setFlag_1(Integer flag_1) {
		this.flag_1 = flag_1;
	}

	public Integer getFlag_2() {
		return flag_2;
	}

	public void setFlag_2(Integer flag_2) {
		this.flag_2 = flag_2;
	}

	public String getSound_Value() {
		return Sound_Value;
	}

	public void setSound_Value(String sound_Value) {
		Sound_Value = sound_Value;
	}

	public String getSound_Label() {
		return Sound_Label;
	}

	public void setSound_Label(String sound_Label) {
		Sound_Label = sound_Label;
	}

	public String getLocation() {
		return Location;
	}

	public void setLocation(String location) {
		Location = location;
	}

	public String getLocation_Label() {
		return Location_Label;
	}

	public void setLocation_Label(String location_Label) {
		Location_Label = location_Label;
	}


	


	public String getPower_usage1() {
		return power_usage1;
	}

	public void setPower_usage1(String power_usage1) {
		this.power_usage1 = power_usage1;
	}

	public String getPower_usage2() {
		return power_usage2;
	}

	public void setPower_usage2(String power_usage2) {
		this.power_usage2 = power_usage2;
	}





	private String MessageXML="";
	
	private String MessageXML1="";
	
	private List<LightEntity> lList;
	
	private List<LightEntity> dList;
	
private List<LightEntity> tList;
	
	private List<LightEntity> hList;
	
	
	private List<LightEntity> tempList;
	
	private List<LightEntity> sList;
	
	
	
	
	
	
	public List<LightEntity> getsList() {
		return sList;
	}

	public void setsList(List<LightEntity> sList) {
		this.sList = sList;
	}

	public List<LightEntity> getTempList() {
		return tempList;
	}

	public void setTempList(List<LightEntity> tempList) {
		this.tempList = tempList;
	}

	public String getsM_Label() {
		return sM_Label;
	}

	public void setsM_Label(String sM_Label) {
		this.sM_Label = sM_Label;
	}

	public String getsM() {
		return sM;
	}

	public void setsM(String sM) {
		this.sM = sM;
	}

	public String getDate_Label() {
		return Date_Label;
	}

	public void setDate_Label(String date_Label) {
		Date_Label = date_Label;
	}

	public String getTime_Label() {
		return Time_Label;
	}

	public void setTime_Label(String time_Label) {
		Time_Label = time_Label;
	}

	public String getLight_Value() {
		return Light_Value;
	}

	public void setLight_Value(String light_Value) {
		Light_Value = light_Value;
	}

	public String getHumidity_Value() {
		return Humidity_Value;
	}

	public void setHumidity_Value(String humidity_Value) {
		Humidity_Value = humidity_Value;
	}

	public List<LightEntity> gettList() {
		return tList;
	}

	public void settList(List<LightEntity> tList) {
		this.tList = tList;
	}

	public List<LightEntity> gethList() {
		return hList;
	}

	public void sethList(List<LightEntity> hList) {
		this.hList = hList;
	}

	public String getTime_Value() {
		return Time_Value;
	}

	public void setTime_Value(String time_Value) {
		Time_Value = time_Value;
	}

	public List<LightEntity> getdList() {
		return dList;
	}

	public void setdList(List<LightEntity> dList) {
		this.dList = dList;
	}

	public String getMessageXML1() {
		return MessageXML1;
	}
	public String getDate_Value() {
		return Date_Value;
	}

	public void setDate_Value(String date_Value) {
		Date_Value = date_Value;
	}
	public void setMessageXML1(String messageXML1) {
		MessageXML1 = messageXML1;
	}

	public String getMessageXML() {
		return MessageXML;
	}

	public void setMessageXML(String messageXML) {
		MessageXML = messageXML;
	}

	public String getP_Name() {
		return p_Name;
	}

	public void setP_Name(String p_Name) {
		this.p_Name = p_Name;
	}


	private String value2="Pot on Cooker";
	private String value3="Add Water";private String value4="Turn Cooker ON";
	private String value5="Turn Cooker OFF";private String value6="Turn Kettle ON";
	private String value7="Turn Kettle OFF";private String value8="Read Instructions";
	private String value9="Add Noodles";private String value10="Add Seasoning";
	private String value11="Place Lid";private String value12="Remove Lid";
	private String value13="Check Noodles";private String value14="Start Stirring";
	private String value15="Stop Stirring";private String value16="Power Level 1 (Around 700W)";
	private String value17="Power Level 2 (Around 1000 W)";private String value18="Power Level 3 (Approx 1130W)";
	private String value19="Power Level 4 (Approx 1237 W)";private String value20="Power Level 5 (Approx 1290 W)";
	private String value21="Power Level 6 (Approx 1400 W)";private String value22="Power Level 7 (Approx 1625 W)";
	private String value23="Power Level 8 (Approx 1752 W)";private String value24="Power Level 9 (Approx 2000W)";
	private String value25="Power Level 10 (Approx 2121 W)";
	
	
	
	public String getValue2() {
		return value2;
	}

	public void setValue2(String value2) {
		this.value2 = value2;
	}

	public String getValue3() {
		return value3;
	}

	public void setValue3(String value3) {
		this.value3 = value3;
	}

	public String getValue4() {
		return value4;
	}

	public void setValue4(String value4) {
		this.value4 = value4;
	}

	public String getValue5() {
		return value5;
	}

	public void setValue5(String value5) {
		this.value5 = value5;
	}

	public String getValue6() {
		return value6;
	}

	public void setValue6(String value6) {
		this.value6 = value6;
	}

	public String getValue7() {
		return value7;
	}

	public void setValue7(String value7) {
		this.value7 = value7;
	}

	public String getValue8() {
		return value8;
	}

	public void setValue8(String value8) {
		this.value8 = value8;
	}

	public String getValue9() {
		return value9;
	}

	public void setValue9(String value9) {
		this.value9 = value9;
	}

	public String getValue10() {
		return value10;
	}

	public void setValue10(String value10) {
		this.value10 = value10;
	}

	public String getValue11() {
		return value11;
	}

	public void setValue11(String value11) {
		this.value11 = value11;
	}

	public String getValue12() {
		return value12;
	}

	public void setValue12(String value12) {
		this.value12 = value12;
	}

	public String getValue13() {
		return value13;
	}

	public void setValue13(String value13) {
		this.value13 = value13;
	}

	public String getValue14() {
		return value14;
	}

	public void setValue14(String value14) {
		this.value14 = value14;
	}

	public String getValue15() {
		return value15;
	}

	public void setValue15(String value15) {
		this.value15 = value15;
	}

	public String getValue16() {
		return value16;
	}

	public void setValue16(String value16) {
		this.value16 = value16;
	}

	public String getValue17() {
		return value17;
	}

	public void setValue17(String value17) {
		this.value17 = value17;
	}

	public String getValue18() {
		return value18;
	}

	public void setValue18(String value18) {
		this.value18 = value18;
	}

	public String getValue19() {
		return value19;
	}

	public void setValue19(String value19) {
		this.value19 = value19;
	}

	public String getValue20() {
		return value20;
	}

	public void setValue20(String value20) {
		this.value20 = value20;
	}

	public String getValue21() {
		return value21;
	}

	public void setValue21(String value21) {
		this.value21 = value21;
	}

	public String getValue22() {
		return value22;
	}

	public void setValue22(String value22) {
		this.value22 = value22;
	}

	public String getValue23() {
		return value23;
	}

	public void setValue23(String value23) {
		this.value23 = value23;
	}

	public String getValue24() {
		return value24;
	}

	public void setValue24(String value24) {
		this.value24 = value24;
	}

	public String getValue25() {
		return value25;
	}

	public void setValue25(String value25) {
		this.value25 = value25;
	}

	public String getMessage() {
		return Message;
	}

	public String getMessage1() {
		return Message1;
	}

	public void setMessage1(String message1) {
		Message1 = message1;
	}

	public void setMessage(String message) {
		Message = message;
	}


	
	



	public List<LightEntity> getlList() {
		return lList;
	}

	public void setlList(List<LightEntity> lList) {
		this.lList = lList;
	}


	
	
	public String valueChanged() {
			
try{
	sM = "";
	sM_Label = "";
	Light_Label = "";
	Date_Label = "";
	Time_Label = "";
	Temp_Label = "";
	Humidity_Label = "";
	Sound_Label = "";
	Light_Value = "";
	Date_Value = "";
	Time_Value = "";
	Temp_Value = "";
	Sound_Value = "";
	Humidity_Value = "";
	Location_Label = "";
	Location = "";
	FLabService service = new FLabService();
	//LightEntity entity = new LightEntity();
	//entity.setMote_id(this.selectedMote);
	
	System.out.println("In bean 1");
	System.out.println(this.selectedMote);
	
	this.lList=service.getLightDetails(this.selectedMote);
	
	this.dList=service.getDateDetails(this.selectedMote);
	
	this.tList=service.getTimeDetails(this.selectedMote);

	this.hList = service.getHumidityDetails(this.selectedMote);
	
	this.tempList = service.getTempDetails(this.selectedMote);
	
	this.sList = service.getSoundDetails(this.selectedMote);
	
	System.out.println(lList.get(0));
	
	System.out.println(dList.get(0));

	System.out.println(tList.get(0));
	
	System.out.println(hList.get(0));
	
	Iterator it = lList.iterator();
	
	Iterator it1 = dList.iterator();
	
	Iterator it2 = tList.iterator();
	
	Iterator it3 = hList.iterator();
	
	Iterator it4 = tempList.iterator();
	
	Iterator it5 = sList.iterator();

	while (it.hasNext()) {
	 
	  this.Light_Value = (String) it.next();
	}
	while (it1.hasNext()){
		this.Date_Value = (String) it1.next();
	}
	
	while (it2.hasNext()){
		this.Time_Value = (String) it2.next();
	}
	
	while (it3.hasNext()){
		this.Humidity_Value = (String) it3.next();
	}
	
	while (it4.hasNext()){
		this.Temp_Value = (String) it4.next();
	}
	
	while (it5.hasNext()){
		this.Sound_Value = (String) it5.next();
	}
	//this.Light_Value=lList.get(0);
	System.out.println("In bean 2");
						
		}
		catch(Exception e){
			e.printStackTrace();
			this.Message="Mote not in operation!!";
			return "fail";
		}
		this.Message="";
		sM = "ZBTM00" + this.selectedMote;
		sM_Label = "Selected Mote";
		Light_Label = "Light (in Lux)";
		Date_Label = "Date";
		Time_Label = "Time";
		Location_Label = "Location";
		Temp_Label = "Temperature (in degree Celsius)";
		Sound_Label = "Sound (in dB)";
		
		if(this.selectedMote == 7)
			Location = "Master Bedroom";
		else if (this.selectedMote == 3)
			Location = "Living Room";
		else if (this.selectedMote == 2)
			Location = "Kitchen";
		else if (this.selectedMote == 5)
			Location = "Bedroom";
		
		Humidity_Label = "Humidity (in %)";
		return "success";
		
		
	   
	}
	
//Turn ON Device 19	
	
public String parseXML() {
	String PU;	
	flag_1=1;
	
	
		try{
			FLabService service = new FLabService();
			service.start();
			PU=service.usage();
			
		System.out.println("In return");
							
				}
				catch(Exception e){
					e.printStackTrace();
					this.MessageXML="Error!!Cannot Perform Operation";
					return "failxml";
				}
				this.MessageXML = "Turned ON";
				this.power_usage1=PU;
				
	//}	//repeat();
				return "successxml";
				
				
			   
			}
/*
public void repeat(){
	String PU;	
	try{
		FLabService service = new FLabService();
		this.power_usage1=service.usage();
		
	System.out.println("In repeat return");
						
			}
			catch(Exception e){
				e.printStackTrace();
				this.MessageXML="Error!!Cannot Perform Operation";
				
			}
			
			repeat();
			//this.MessageXML = "Turned ON";
			
			
}*/
	
//Turn OFF Device 19
public String parseXML1() {
	flag_1=0;
	
	try{
		FLabService service = new FLabService();
		service.start1();
		
	System.out.println("In return");
						
			}
			catch(Exception e){
				e.printStackTrace();
				this.MessageXML="Error!!Cannot Perform Operation";
				return "failxml";
			}
			this.MessageXML = "Turned OFF";
			this.power_usage1="0";
			return "successxml";
			
			
		   
		}
//Turn ON Device 24

public String parseXML2() {
	String PU;
	try{
		FLabService service = new FLabService();
		service.start2();
		PU=service.usage2();
	System.out.println("In return");
						
			}
			catch(Exception e){
				e.printStackTrace();
				this.MessageXML1="Error!!Cannot Perform Operation";
				return "failxml";
			}
			this.MessageXML1 = "Turned ON";
			this.power_usage2=PU;
			return "successxml";
			
			
		   
		}

//Turn OFF Device 24
public String parseXML3() {

try{
	FLabService service = new FLabService();
	service.start3();
	
System.out.println("In return");
					
		}
		catch(Exception e){
			e.printStackTrace();
			this.MessageXML1="Error!!Cannot Perform Operation";
			return "failxml";
		}
		this.MessageXML1 = "Turned OFF";
		this.power_usage2="0";
		return "successxml";
		
		
	   
	}
	public String experiment() {
		
		try{
			this.Message = "";
			this.Message1 = "";
			FLabService service = new FLabService();
			//LightEntity entity = new LightEntity();
			//entity.setMote_id(this.selectedMote);
			
			int ret = service.addToDatabase(this.p_Name);
			
			System.out.println("In return");
							System.out.println(ret);	
				}
				catch(Exception e){
					e.printStackTrace();
					return "fail";
				}
				this.Message = "Started";
				return "success";
				
				
			   
			}
	
public String experiment1() {
		
		try{
			this.Message = "";
			this.Message1 = "";
			FLabService service = new FLabService();
			//LightEntity entity = new LightEntity();
			//entity.setMote_id(this.selectedMote);
			
			int ret = service.addToDatabase1(this.p_Name);
			
			System.out.println("In return");
							System.out.println(ret);	
				}
				catch(Exception e){
					e.printStackTrace();
					return "fail";
				}
				this.Message1 = "Stopped";
				return "success";
				
				
			   
			}
	
public String experiment2() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value2,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}

public String experiment3() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value3,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}
public String experiment4() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value4,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}
public String experiment5() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value5,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}


public String experiment6() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value6,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}
public String experiment7() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value7,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}
public String experiment8() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value8,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}

public String experiment9() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value9,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}
public String experiment10() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value10,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}

public String experiment11() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value11,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}

public String experiment12() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value12,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}


public String experiment13() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value13,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}
public String experiment14() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value14,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}


public String experiment15() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value15,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}
public String experiment16() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value16,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}


public String experiment17() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value17,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}
public String experiment18() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value18,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}

public String experiment19() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value19,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}


public String experiment20() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value20,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}
public String experiment21() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value21,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}


public String experiment22() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value22,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}

public String experiment23() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value23,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}
public String experiment24() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value24,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}

public String experiment25() {
	
	try{
		
		FLabService service = new FLabService();
		int ret = service.addToDatabase_Generic(this.value25,this.p_Name);
		System.out.println("In return");
		System.out.println(ret);	
			}
			catch(Exception e){
				e.printStackTrace();
				return "fail";
			}
			return "success";
	   
		}
public String getLight_Label() {
		return Light_Label;
	}

	public void setLight_Label(String light_Label) {
		Light_Label = light_Label;
	}

	public String getProximity_Label() {
		return Proximity_Label;
	}

	public void setProximity_Label(String proximity_Label) {
		Proximity_Label = proximity_Label;
	}

	public String getTemp_Label() {
		return Temp_Label;
	}

	public void setTemp_Label(String temp_Label) {
		Temp_Label = temp_Label;
	}

	public String getHumidity_Label() {
		return Humidity_Label;
	}

	public void setHumidity_Label(String humidity_Label) {
		Humidity_Label = humidity_Label;
	}

	


	public String getProximity_Value() {
		return Proximity_Value;
	}


	public void setProximity_Value(String proximity_Value) {
		Proximity_Value = proximity_Value;
	}


	public String getTemp_Value() {
		return Temp_Value;
	}


	public void setTemp_Value(String temp_Value) {
		Temp_Value = temp_Value;
	}


	List<SelectItem> moteList=new ArrayList<SelectItem>();
	
	
	public FLabBean()
	{
		
		//moteList.add(new SelectItem("--Select--"));
		moteList.add(new SelectItem(1));
		moteList.add(new SelectItem(2));
		moteList.add(new SelectItem(3));
		moteList.add(new SelectItem(4));
		moteList.add(new SelectItem(5));
		moteList.add(new SelectItem(6));
		moteList.add(new SelectItem(7));
		moteList.add(new SelectItem(8));
		moteList.add(new SelectItem(9));
		moteList.add(new SelectItem(10));
	}


	


	public Integer getSelectedMote() {
		return selectedMote;
	}

	public void setSelectedMote(Integer selectedMote) {
		this.selectedMote = selectedMote;
	}

	public List<SelectItem> getMoteList() {
		return moteList;
	}


	public void setMoteList(List<SelectItem> moteList) {
		this.moteList = moteList;
	}
	
	
}
